﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
using MathematicallySafe.HeadCounter.Data.Common;

namespace MathematicallySafe.HeadCounter.Data.Models
{
    [Serializable]
    public class LootItem
    {
        private string _boss;
        private string _zone;

        [XmlAttribute]
        public int ID { get; set; }

        [XmlAttribute]
        public string Name { get; set; }

        [XmlAttribute]
        public LootSlot Slot { get; set; }

        [XmlAttribute]
        public bool Unique { get; set; }

        [XmlAttribute]
        public ItemSubClass SubClass { get; set; }

        [XmlAttribute]
        public int iLevel { get; set; }

        [XmlAttribute]
        public string Icon { get; set; }

        [XmlAttribute]
        public string Zone
        {
            get
            {
                if (string.IsNullOrEmpty(_zone)) return "Trash";
                else return _zone;
            }
            set { _zone = value; }
        }

        [XmlAttribute]
        public string Boss
        {
            get
            {
                if (string.IsNullOrEmpty(_boss)) return "Trash Drops";
                else return _boss;
            }
            set { _boss = value; }
        }

        [XmlIgnore]
        public Uri LootUri
        {
            get { return new Uri("http://www.wowhead.com/?item=" + ID); }
        }

        [XmlIgnore]
        public Uri IconSource
        {
            get
            {
                return new Uri(Directory.GetCurrentDirectory() + "//icons//" + Icon + ".jpg", UriKind.Absolute);
            }
        }

        [XmlIgnore]
        public int? Stamina { get; set; }

        [XmlElement("Stamina", IsNullable = false)]
        public string SerializableStamina
        {
            get { return Stamina == null ? null : Stamina.ToString(); }
            set { Stamina = Convert.ToInt32(value); }
        }

        [XmlIgnore]
        public int? Intellect { get; set; }

        [XmlElement("Intellect", IsNullable = false)]
        public string SerializableIntellect
        {
            get { return Intellect == null ? null : Intellect.ToString(); }
            set { Intellect = Convert.ToInt32(value); }
        }

        [XmlIgnore]
        public int? Agility { get; set; }

        [XmlElement("Agility", IsNullable = false)]
        public string SerializableAgility
        {
            get { return Agility == null ? null : Agility.ToString(); }
            set { Agility = Convert.ToInt32(value); }
        }

        [XmlIgnore]
        public int? Spirit { get; set; }

        [XmlElement("Spirit", IsNullable = false)]
        public string SerializableSpirit
        {
            get { return Spirit == null ? null : Spirit.ToString(); }
            set { Spirit = Convert.ToInt32(value); }
        }

        [XmlIgnore]
        public int? Strength { get; set; }

        [XmlElement("Strength", IsNullable = false)]
        public string SerializableStrength
        {
            get { return Strength == null ? null : Strength.ToString(); }
            set { Strength = Convert.ToInt32(value); }
        }

        [XmlElement]
        public DamageData Damage { get; set; }

        [XmlElement]
        public List<SocketType> Sockets { get; set; }

        [XmlElement]
        public List<String> Bonuses { get; set; }
    }

    [Serializable]
    public class DamageData
    {
        [XmlAttribute]
        public int Min { get; set; }
        [XmlAttribute]
        public int Max { get; set; }
        [XmlAttribute]
        public double Speed { get; set; }
        [XmlAttribute]
        public double DPS { get; set; }
    }

    public enum SocketType
    {
        Meta, Red, Blue, Yellow
    }
}